outlook: Authenticate emulator Graph requests - #3088
Open
gentlemandev wants to merge 1 commit into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/web/utils/outlook/client.ts">
<violation number="1" location="apps/web/utils/outlook/client.ts:286">
P1: Emulator Graph requests fail before reaching the HTTP server because the replacement authentication handler has no `nextMiddleware`: replacing `middleware[0]` discards the linked first handler, but this new instance never receives `setNext`. Linking it to `middleware[1]` (or otherwise preserving the existing chain) keeps the default retry, redirect, telemetry, and HTTP handlers while allowing the bearer header to be added.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
|
||
| // Graph SDK 3.x only authenticates HTTPS custom hosts, while emulate.dev | ||
| // intentionally serves its local Microsoft endpoint over HTTP. | ||
| middleware[0] = new MicrosoftEmulatorAuthenticationHandler(accessToken); |
Contributor
There was a problem hiding this comment.
P1: Emulator Graph requests fail before reaching the HTTP server because the replacement authentication handler has no nextMiddleware: replacing middleware[0] discards the linked first handler, but this new instance never receives setNext. Linking it to middleware[1] (or otherwise preserving the existing chain) keeps the default retry, redirect, telemetry, and HTTP handlers while allowing the bearer header to be added.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/web/utils/outlook/client.ts, line 286:
<comment>Emulator Graph requests fail before reaching the HTTP server because the replacement authentication handler has no `nextMiddleware`: replacing `middleware[0]` discards the linked first handler, but this new instance never receives `setNext`. Linking it to `middleware[1]` (or otherwise preserving the existing chain) keeps the default retry, redirect, telemetry, and HTTP handlers while allowing the bearer header to be added.</comment>
<file context>
@@ -258,3 +275,41 @@ export function getLinkingOAuth2Url() {
+
+ // Graph SDK 3.x only authenticates HTTPS custom hosts, while emulate.dev
+ // intentionally serves its local Microsoft endpoint over HTTP.
+ middleware[0] = new MicrosoftEmulatorAuthenticationHandler(accessToken);
+
+ return middleware;
</file context>
Suggested change
| middleware[0] = new MicrosoftEmulatorAuthenticationHandler(accessToken); | |
| const authenticationHandler = new MicrosoftEmulatorAuthenticationHandler( | |
| accessToken, | |
| ); | |
| authenticationHandler.setNext(middleware[1]); | |
| middleware[0] = authenticationHandler; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
Authenticate Microsoft Graph requests to the local HTTP emulator while leaving the production Graph client path unchanged.
What changed
Root cause
QA for #3081 found that the Graph SDK 3.x authentication middleware removes authorization from HTTP custom hosts. The emulator token itself was valid, but app requests reached the Microsoft emulator without an Authorization header and returned 401.
Validation
pnpm test utils/outlook/client.test.ts utils/outlook/client.emulator.test.ts(4 tests)pnpm test utils/outlook/message.test.ts(63 tests)pnpm test-integration provider-operations(19 tests)pnpm exec ultracite check ...on the affected and original PR files/api/messagesreturned the seeded messages and AI Chat returned the expected text-search result